-- @owner:yangjian
-- @date:2024-4-6
-- @testpoint:1.去除大对象使用限制，测试lo_open，lowrite和loread函数共同使用(只读和只写表现是否正常)，合理报错
 
--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_function_case0008_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_function_case0008_1();

--环境准备
drop table if exists t_opengauss_large_object_function_case0008_1 cascade;
CREATE TABLE t_opengauss_large_object_function_case0008_1 (loid oid,fd int);
INSERT INTO t_opengauss_large_object_function_case0008_1 (loid) SELECT lo_create(100);

--step1:测试lo_open只写的表现;expect:成功
begin;
SELECT lo_open(100,CAST(x'20000' AS integer));
select lowrite (0,'aaaaaaaaaa');
select loread (0, 6);
end;
/

--step2:测试lo_open只读的表现;expect:失败
begin;
SELECT lo_open(100,CAST(x'40000' AS integer));
select loread (0, 6);
select lowrite (0,'aaaaaaaaaa');
end;
/
end;
--清理环境
select lo_unlink(loid) from t_opengauss_large_object_function_case0008_1;
select f_opengauss_large_object_function_case0008_1();
drop table if exists t_opengauss_large_object_function_case0008_1 cascade;
drop function f_opengauss_large_object_function_case0008_1();
